
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <assert.h>
#include <cstdio>
#include "Completion.h"
#include "String.h"
#include "Value.h"

// empty for a target can just be the empty string, because it is
// not possible to label a statement with the empty string (I hope)
String* Completion::empty = new String("");

Completion::Completion(CompletionType type, Value* value, String* target)
    :m_type(type), m_value(value), m_target(target)
{}

ValueType Completion::getType() const
{
    return VT_COMPLETION;
}

CompletionType Completion::type() const
{
    return m_type;
}

Value* Completion::value() const
{
    return m_value;
}

String* Completion::target() const
{
    return m_target;
}

bool Completion::isException() const
{
    return m_type == CT_THROW;
}

Value* Completion::getValue()
{
    // if this is an exception, just return it. Else
    // we should not be calling getValue
    if (this->isException())
    {
        fprintf(stderr, "Warning: getValue called on an exception\n");
        return this;
    }
    assert(false);
    return this;
}

